home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / CheckBoxLink / CheckBoxLink.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  7.4 KB  |  320 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Button;
  4. import java.awt.Checkbox;
  5. import java.awt.Color;
  6. import java.awt.Component;
  7. import java.awt.Container;
  8. import java.awt.FlowLayout;
  9. import java.awt.event.ActionEvent;
  10. import java.awt.event.ActionListener;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.net.MalformedURLException;
  14. import java.net.URL;
  15. import java.net.URLEncoder;
  16. import java.util.EventObject;
  17.  
  18. public class CheckBoxLink extends Applet implements MouseListener, ActionListener {
  19.    // $FF: renamed from: wi int
  20.    private int field_0;
  21.    // $FF: renamed from: he int
  22.    private int field_1;
  23.    private int n_link = 1;
  24.    // $FF: renamed from: cb java.awt.Checkbox[]
  25.    private Checkbox[] field_2;
  26.    private String buttonText;
  27.    private String statusBarText;
  28.    private AudioClip sound;
  29.    private AudioClip clicSound;
  30.    private boolean loopSound;
  31.    private Color backColor;
  32.    private Color enterBackColor;
  33.    private Color checkColor;
  34.    private Color enterCheckColor;
  35.    private Color buttonColor;
  36.    private Color enterButtonColor;
  37.    // $FF: renamed from: b java.awt.Button
  38.    private Button field_3;
  39.  
  40.    public String getAppletInfo() {
  41.       return "Name: CheckBoxLink\r\nAuthor: Taiji Software\r\n";
  42.    }
  43.  
  44.    public void register() {
  45.       try {
  46.          URL u = new URL("http://www.taijisoftware.com");
  47.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  48.          this.stop();
  49.       } catch (Exception e) {
  50.          System.out.println(e);
  51.          this.stop();
  52.       }
  53.    }
  54.  
  55.    public void init() {
  56.       String codeBase = null;
  57.  
  58.       try {
  59.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  60.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  61.          codeBase = codeBase.toUpperCase();
  62.       } catch (Exception var9) {
  63.       }
  64.  
  65.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  66.          String regCode = ((Applet)this).getParameter("registration_code");
  67.          if (regCode == null) {
  68.             regCode = ((Applet)this).getParameter("reg_domain");
  69.             if (regCode == null) {
  70.                this.register();
  71.             } else {
  72.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  73.                   codeBase = "WWW." + codeBase;
  74.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  75.                   codeBase = codeBase.substring(4);
  76.                }
  77.  
  78.                char[] chars = new char[codeBase.length()];
  79.                codeBase.getChars(0, codeBase.length(), chars, 0);
  80.                String key = new String("haricot");
  81.                char[] chars2 = new char[key.length()];
  82.                key.getChars(0, key.length(), chars2, 0);
  83.  
  84.                for(int i = 0; i < codeBase.length(); ++i) {
  85.                   int j;
  86.                   if (i >= key.length()) {
  87.                      j = i - key.length() * (i / key.length());
  88.                   } else {
  89.                      j = i;
  90.                   }
  91.  
  92.                   chars[i] += chars2[j];
  93.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  94.                }
  95.  
  96.                String res = new String(chars);
  97.                if (!res.equalsIgnoreCase(regCode)) {
  98.                   this.register();
  99.                }
  100.             }
  101.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  102.             this.register();
  103.          }
  104.       }
  105.  
  106.       this.getParameters();
  107.       this.field_2 = new Checkbox[this.n_link];
  108.       ((Container)this).setLayout(new FlowLayout());
  109.       String s = ((Applet)this).getParameter("checkboxes_color");
  110.       if (s != null && s.substring(0, 1).equals("#")) {
  111.          s = s.substring(1);
  112.          int l = Integer.parseInt(s, 16);
  113.          this.checkColor = new Color(l);
  114.       }
  115.  
  116.       for(int i = 0; i < this.n_link; ++i) {
  117.          this.field_2[i] = new Checkbox(((Applet)this).getParameter("text" + Integer.toString(i + 1)));
  118.          String initialState = ((Applet)this).getParameter("checked" + Integer.toString(i + 1));
  119.          if (initialState != null) {
  120.             if (initialState.equalsIgnoreCase("no")) {
  121.                this.field_2[i].setState(false);
  122.             }
  123.          } else {
  124.             this.field_2[i].setState(true);
  125.          }
  126.  
  127.          this.field_2[i].setBackground(this.checkColor);
  128.          ((Container)this).add(this.field_2[i]);
  129.       }
  130.  
  131.       this.field_3 = new Button(this.buttonText);
  132.       if (this.buttonColor != null) {
  133.          this.field_3.setBackground(this.buttonColor);
  134.       } else {
  135.          this.buttonColor = this.field_3.getBackground();
  136.       }
  137.  
  138.       this.field_3.addActionListener(this);
  139.       ((Container)this).add(this.field_3);
  140.       if (this.sound != null) {
  141.          if (this.loopSound) {
  142.             this.sound.loop();
  143.             return;
  144.          }
  145.  
  146.          this.sound.play();
  147.       }
  148.  
  149.    }
  150.  
  151.    public void getParameters() {
  152.       this.field_0 = ((Component)this).getSize().width;
  153.       this.field_1 = ((Component)this).getSize().height;
  154.       this.backColor = this.getColor("background_color");
  155.       ((Component)this).setBackground(this.backColor);
  156.       this.enterBackColor = this.getColor("enter_background_color");
  157.       this.enterCheckColor = this.getColor("enter_checkboxes_color");
  158.       this.buttonColor = this.getColor("button_color");
  159.       this.enterButtonColor = this.getColor("enter_button_color");
  160.       this.buttonText = ((Applet)this).getParameter("button_text");
  161.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  162.       if (this.buttonText == null) {
  163.          this.buttonText = "Go !!";
  164.       }
  165.  
  166.       String s = ((Applet)this).getParameter("number");
  167.       if (s != null) {
  168.          this.n_link = Integer.parseInt(s);
  169.       }
  170.  
  171.       s = ((Applet)this).getParameter("sound_name");
  172.       if (s != null) {
  173.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  174.       }
  175.  
  176.       s = ((Applet)this).getParameter("loop_sound");
  177.       if (s != null) {
  178.          if (s.equals("yes")) {
  179.             this.loopSound = true;
  180.          } else {
  181.             this.loopSound = false;
  182.          }
  183.       }
  184.  
  185.       s = ((Applet)this).getParameter("clic_sound_name");
  186.       if (s != null) {
  187.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  188.       }
  189.  
  190.    }
  191.  
  192.    public Color getColor(String param) {
  193.       String s = ((Applet)this).getParameter(param);
  194.       if (s != null) {
  195.          if (s.substring(0, 1).equals("#")) {
  196.             s = s.substring(1);
  197.             int i = Integer.parseInt(s, 16);
  198.             return new Color(i);
  199.          } else {
  200.             return null;
  201.          }
  202.       } else {
  203.          return null;
  204.       }
  205.    }
  206.  
  207.    public void actionPerformed(ActionEvent event) {
  208.       if (((EventObject)event).getSource() instanceof Button) {
  209.          if (this.clicSound != null) {
  210.             this.clicSound.play();
  211.          }
  212.  
  213.          String target = ((Applet)this).getParameter("target");
  214.          if (target == null) {
  215.             target = "_blank";
  216.          }
  217.  
  218.          for(int i = 0; i < this.n_link; ++i) {
  219.             if (this.field_2[i].getState()) {
  220.                URL u = this.giveURL(((Applet)this).getParameter("link" + Integer.toString(i + 1)));
  221.                ((Applet)this).getAppletContext().showDocument(u, target);
  222.             }
  223.          }
  224.  
  225.       }
  226.    }
  227.  
  228.    public void stop() {
  229.       if (this.sound != null) {
  230.          this.sound.stop();
  231.       }
  232.  
  233.    }
  234.  
  235.    public URL giveURL(String url) {
  236.       try {
  237.          if (url.toUpperCase().startsWith("HTTP")) {
  238.             return new URL(url);
  239.          } else if (url.toUpperCase().startsWith("FTP")) {
  240.             int p = url.indexOf(":");
  241.             int p2 = url.indexOf(":", p + 1);
  242.             if (p2 != -1) {
  243.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  244.             }
  245.  
  246.             p = url.indexOf("%40");
  247.             if (p != -1) {
  248.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  249.             }
  250.  
  251.             return new URL(url);
  252.          } else {
  253.             return new URL(((Applet)this).getCodeBase(), url);
  254.          }
  255.       } catch (MalformedURLException e) {
  256.          System.out.println(e);
  257.          return null;
  258.       }
  259.    }
  260.  
  261.    public void mouseClicked(MouseEvent e) {
  262.    }
  263.  
  264.    public void mouseEntered(MouseEvent e) {
  265.       if (this.statusBarText != null) {
  266.          ((Applet)this).showStatus(this.statusBarText);
  267.       }
  268.  
  269.       if (this.enterBackColor != null) {
  270.          ((Component)this).setBackground(this.enterBackColor);
  271.          ((Component)this).repaint();
  272.       }
  273.  
  274.       if (this.enterButtonColor != null) {
  275.          this.field_3.setBackground(this.enterButtonColor);
  276.          ((Component)this).repaint();
  277.       }
  278.  
  279.       if (this.enterCheckColor != null) {
  280.          for(int i = 0; i < this.n_link; ++i) {
  281.             this.field_2[i].setBackground(this.enterCheckColor);
  282.          }
  283.  
  284.          ((Component)this).repaint();
  285.       }
  286.  
  287.    }
  288.  
  289.    public void mouseExited(MouseEvent e) {
  290.       if (this.enterBackColor != null) {
  291.          ((Component)this).setBackground(this.backColor);
  292.          ((Component)this).repaint();
  293.       }
  294.  
  295.       if (this.enterCheckColor != null) {
  296.          for(int i = 0; i < this.n_link; ++i) {
  297.             this.field_2[i].setBackground(this.checkColor);
  298.          }
  299.  
  300.          ((Component)this).repaint();
  301.       }
  302.  
  303.       if (this.enterButtonColor != null) {
  304.          this.field_3.setBackground(this.buttonColor);
  305.          ((Component)this).repaint();
  306.       }
  307.  
  308.    }
  309.  
  310.    public void mousePressed(MouseEvent e) {
  311.    }
  312.  
  313.    public void mouseReleased(MouseEvent e) {
  314.    }
  315.  
  316.    public CheckBoxLink() {
  317.       ((Component)this).addMouseListener(this);
  318.    }
  319. }
  320.